<?php

/**
 * Solicitud filter form base class.
 *
 * @package    BecArTe
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseSolicitudFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'fecha'               => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'estado'              => new sfWidgetFormChoice(array('choices' => array('' => '', 'En Presentación' => 'En Presentación', 'Vencida' => 'Vencida', 'En Evaluación' => 'En Evaluación', 'Aprobada' => 'Aprobada', 'Rechazada' => 'Rechazada'))),
      'observacion'         => new sfWidgetFormFilterInput(),
      'alumno_id'           => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('alumno'), 'add_empty' => true)),
      'beca_id'             => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('beca'), 'add_empty' => true)),
      'created_at'          => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'          => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'created_by'          => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Creator'), 'add_empty' => true)),
      'updated_by'          => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Updator'), 'add_empty' => true)),
      'version'             => new sfWidgetFormFilterInput(),
      'acreditaciones_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Acreditacion')),
    ));

    $this->setValidators(array(
      'fecha'               => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDateTime(array('required' => false)))),
      'estado'              => new sfValidatorChoice(array('required' => false, 'choices' => array('En Presentación' => 'En Presentación', 'Vencida' => 'Vencida', 'En Evaluación' => 'En Evaluación', 'Aprobada' => 'Aprobada', 'Rechazada' => 'Rechazada'))),
      'observacion'         => new sfValidatorPass(array('required' => false)),
      'alumno_id'           => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('alumno'), 'column' => 'id')),
      'beca_id'             => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('beca'), 'column' => 'id')),
      'created_at'          => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'          => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'created_by'          => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Creator'), 'column' => 'id')),
      'updated_by'          => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Updator'), 'column' => 'id')),
      'version'             => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'acreditaciones_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Acreditacion', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('solicitud_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addAcreditacionesListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.relSolicitudAcreditacion relSolicitudAcreditacion')
      ->andWhereIn('relSolicitudAcreditacion.acreditacion_id', $values)
    ;
  }

  public function getModelName()
  {
    return 'Solicitud';
  }

  public function getFields()
  {
    return array(
      'id'                  => 'Number',
      'fecha'               => 'Date',
      'estado'              => 'Enum',
      'observacion'         => 'Text',
      'alumno_id'           => 'ForeignKey',
      'beca_id'             => 'ForeignKey',
      'created_at'          => 'Date',
      'updated_at'          => 'Date',
      'created_by'          => 'ForeignKey',
      'updated_by'          => 'ForeignKey',
      'version'             => 'Number',
      'acreditaciones_list' => 'ManyKey',
    );
  }
}
